<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<div id="app">
    <div>姓：<input type="text" v-model="firstName"></div>
    <div>名：<input type="text" v-model="lastName"></div>
    <div>全名：<input type="text" v-model="fullName"></div>
</div>
<script src="../../javascript//vue.js"></script>
<script>

    const vm = new Vue({
        el: "#app",
        data() {
            return {
                firstName: "陶",
                lastName: "品奇"
            }
        },
        computed: {
            fullName: {
                // 当读取fullName时get会被执行
                get() {
                    return this.firstName + '-' + this.lastName
                },
                // 当修改fullName时set会被执行，同时传入修改后的值，修改前的值（set执行时要让原数据也发生变化）
                set(newValue, oldValue) {
                    const newName = newValue.split("-")
                    console.log(newName)
                    this.firstName = newName[0]
                    this.lastName = newName[newName.length - 1]
                }
            }
        }
    })
</script>
</body>

</html>